package com.galaxy.order.controller;

import com.galaxy.order.domain.OrderDetail;
import com.galaxy.order.service.OrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order-detail")
public class OrderDetailController {
    @Autowired
    private OrderDetailService orderDetailService;

    @PostMapping
    public OrderDetail create(@RequestBody OrderDetail orderDetail) {
        orderDetailService.save(orderDetail);
        return orderDetail;
    }

    @PutMapping
    public OrderDetail update(@RequestBody OrderDetail orderDetail) {
        orderDetailService.updateById(orderDetail);
        return orderDetail;
    }

    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable Long id) {
        return orderDetailService.removeById(id);
    }

    @GetMapping("/{id}")
    public OrderDetail getById(@PathVariable Long id) {
        return orderDetailService.getById(id);
    }
}
